using System;
using System.Collections.Generic;
using System.Text;


public class CSharpCalculator
{
    public CSharpCalculator()
    {
    }

    int currentNumber = 0;
    int currentStack = 0;

    /*
     * 0 - PLUS
     * 1 - MINUS
     * 2 - MULT
     * 3 - DIV
     */ 
    int currentOperation = -1;

    public String buttonPressed(int buttonType)
    {
        switch (buttonType)
        {
            case 0:
                return this.processNumberPressing(0);
            case 1:
                return this.processNumberPressing(1);
            case 2:
                return this.processNumberPressing(2);
            case 3:
                return this.processNumberPressing(3);
            case 4:
                return this.processNumberPressing(4);
            case 5:
                return this.processNumberPressing(5);
            case 6:
                return this.processNumberPressing(6);
            case 7:
                return this.processNumberPressing(7);
            case 8:
                return this.processNumberPressing(8);
            case 9:
                return this.processNumberPressing(9);

            case 10://PLUS
                return this.processOperationPressing(0);
            case 11://MINUS
                return this.processOperationPressing(1);
            case 12://MULT
                return this.processOperationPressing(2);
            case 13://DIV
                return this.processOperationPressing(3);

            case 14://EQUALS
                return this.processEqualsPressing();

            default:
                return "";
        }
    }

    private String processNumberPressing(int numberPressed)
    {
        if (this.currentNumber == 0)
        {
            this.currentNumber = numberPressed;
        }
        else
        {
            String currentNumberString = Convert.ToString(this.currentNumber);
            currentNumberString += numberPressed;

            this.currentNumber = Convert.ToInt16(currentNumberString);
            
        }

        String result = Convert.ToString(this.currentNumber);
        return result;
    }

    private String processOperationPressing(int operationType)
    {
        this.currentStack = this.currentNumber;
        this.currentNumber = 0;
        this.currentOperation = operationType;

        return "";
    }

    private String processEqualsPressing()
    {
        if (this.currentOperation == -1)
        {
            throw new InvalidOperationException();
        }
        else
        {
            int result = 0;

            switch (this.currentOperation)
            {
                case 0://PLUS
                    result = this.currentStack + this.currentNumber;
                    break;
                case 1://MINUS
                    result = this.currentStack - this.currentNumber;
                    break;
                case 2://MULT
                    result = this.currentStack * this.currentNumber;
                    break;
                case 3://DIV
                    if (this.currentStack == 0)
                    {
                        result = 0;
                        break;
                    }
                    else
                    {
                        result = this.currentStack / this.currentNumber;
                        break;
                    }
            }

            this.currentNumber = result;
            return Convert.ToString(result);
        }
    }




}

